import os
from django.conf.urls.defaults import patterns, include, url

from cmsdj import settings
from cmsdj.feeds import LatestContentFeed
from cmsdj.sitemap import SitemapContenidos, SitemapCategorias
from django.contrib import admin
from django.views.generic.simple import direct_to_template

from cmsdj.cfg.models import SiteCfg
admin.autodiscover()

template_dir = SiteCfg.get_template_dir()
template_name = os.path.basename(template_dir)
uploads_dir = SiteCfg.current_cfg().upload_dir

mapas = {'contenidos' : SitemapContenidos,
         'categorias' : SitemapCategorias,
         }
    
urlpatterns = patterns('',
    (r'^$', 'core.views.index'),

    (r'^search/', include('cmsdj.haystack.urls')),

    (r'^category/list/$','categories.views.list_categories'),
    (r'^category/(?P<slug>[\w-]+)/$','categories.views.details'),
    
    (r'^content/(?P<slug>[\w-]+)/$','content.views.details'),
    (r'^content/(?P<slug>[\w-]+)/toprint/$','content.views.details_to_print'),
    (r'^content/page/(?P<page>\d+)/$', 'core.views.index'),
    
    (r'^comments/', include('django.contrib.comments.urls')),
    
    url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
    url(r'^admin/', include(admin.site.urls)),
        
    (r'^cv$', direct_to_template, {'template': settings.STATIC_URL + 'curr/carlos-martin-sanchez.cv.html', 'mimetype':'text/html'}),
    (r'^robots.txt$', direct_to_template, {'template': settings.STATIC_URL + 'robots.txt', 'mimetype':'text/plain'}),
    
    (r'^'+uploads_dir+'/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.STATIC_URL+uploads_dir+'/'}),
    (r'^media/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.STATIC_URL}),
    (r'^media/curr/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.STATIC_URL + 'curr/'}),
    (r'^media/prettify/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.STATIC_URL + 'prettify/'}),

    (r'^fonts/(?P<path>.*)$', 'django.views.static.serve', {'document_root': template_dir+ '/fonts/'}),
    (r'^css/(?P<path>.*)$', 'django.views.static.serve', {'document_root': template_dir + '/css/'}),
    (r'^img/(?P<path>.*)$', 'django.views.static.serve', {'document_root': template_dir + '/img/'}),
    
    (r'^feeds/content/last/$|^rss/$|^feeds/$', LatestContentFeed()),
    (r'^sitemap.xml$', 'django.contrib.sitemaps.views.sitemap', {'sitemaps': mapas}),

)
